#define _CRT_SECURE_NO_WARNINGS 1
#include <vector>
using namespace std;
class Solution {
public:
    int getCoins(vector<int>& coins)
    {
        coins.insert(coins.begin(), 1);
        coins.push_back(1);
        vector<vector<int>> dp(coins.size(), vector<int>(coins.size(), 0));
        for (int i = coins.size() - 2;i >= 1;--i)
        {
            for (int j = i;j < coins.size() - 1;++j)
            {
                for (int k = i;k <= j;++k)
                {
                    //cout<<"i="<<i<<",j="<<j<<",k="<<k<<endl;
                    dp[i][j] = max(dp[i][j], dp[i][k - 1] + dp[k + 1][j] + coins[k] * coins[i - 1] * coins[j + 1]);
                }
            }
        }
        return dp[1][coins.size() - 2];
    }
};